<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>考勤</title>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">考勤</div>
		</div>

	</div>
	<div class="easyui-panel" style="width: 100%; margin: 0 auto;">
		<div style="padding: 10px 60px 20px 60px">
			<form id="ff" method="post">
				<table cellpadding="5" style="margin: auto;">
					<tr>
						<td style="width: 100px;">成员：</td>
						<td colspan="3">
							<input style="width: 100%; height: 80px" id="levelchild" name="levelchild" class="easyui-combotree"
								data-options="
							    valueField: 'id',
							    textField: 'name',
							    multiline:true,
							    multiple:true,
							   	url:'../usertree.do',
							    onSelect: function(rec){
							    
							    },
							    editable:false">
						</td>
					</tr>
					<tr>
						<td colspan="4">
							<a href="javascript:void(0)" class="d-btn btn-green" style="float: right;" onclick="newpro()">添加临时工</a>
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">上传图片：</td>
						<td>
							<input class="easyui-filebox"
								data-options="prompt:'添加图片', buttonText:'选择图片',multiple:true,accept:'image/*'" id="images"
								name="images" style="width: 100%;" />
						</td>
					</tr>
				</table>
			</form>
			<div style="text-align: center; margin-top: 30px;">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">保存</a>
			</div>
		</div>
	</div>

	<div id="childDlg" class="easyui-dialog info_dialog" closed="true"
		style="width: 100%; padding: 10px 20px; max-height: 80%; overflow-y: auto;" buttons="#child-dlg-buttons">
		<form id="childFm" method="post">
			<div class="content_container">
				<table class="content_table" id="display_table">
					<tr>
						<td style="width: 100px;">姓名：</td>
						<td>
							<input type="text" class="easyui-textbox" id="name" name="name" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">工号：</td>
						<td>
							<input type="text" class="easyui-textbox" id="jobno" name="jobno" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">身份证号：</td>
						<td>
							<input type="text" class="easyui-textbox" id="idcard" name="idcard" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">手机号：</td>
						<td>
							<input type="text" class="easyui-textbox" id="mobile" name="mobile" style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">性别：</td>
						<td>
							<select class="easyui-combobox" id="sex" data-options="panelHeight: 'auto'" name="sex"
								style="width: 100%;" editable="false">
								<option value="男">男</option>
								<option value="女">女</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">部门：</td>
						<td>
							<input style="width: 100%;" id="department" name="department" class="easyui-combobox" editable="false"
								data-options="
							    valueField: 'id',
							    textField: 'name',
							    onSelect: function(rec){
							    	companyid=rec.companyid;
							    },
							    panelHeight: 'auto'">
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">日薪：</td>
						<td>
							<input type="text" class="easyui-textbox" id="salary" name="salary"
								style="width: 100%;" />
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div id="child-dlg-buttons">
		<a href="# " class="easyui-linkbutton " onclick="saveChild()">保存</a>
		<a href="# " class="easyui-linkbutton btn-cancel " onclick="javascript:$('#childDlg').dialog('close')">取消</a>
	</div>

</body>
<script th:inline="javascript">
	var projectItemChild = [[${projectItemChild}]];
	var projectItem = [[${projectItem}]];
	var date = [[${date}]];
	
	function newpro(){
		var url = '../departmentbyprojectitem?projectitemid='+projectItem.id;
		$('#department').combobox('reload', url);
		$("#childDlg").dialog('open').dialog('setTitle', '添加临时工');
		$("#childFm").form('clear');
		currentChild = {};
	}
	function saveChild() {
		var formData = new FormData();
		formData.append("name",$("#name").textbox('getValue'));
		formData.append("jobno",$("#jobno").textbox('getValue'));
		formData.append("idcard",$("#idcard").textbox('getValue'));
		formData.append("sex",$("#sex").combobox('getValue'));
		formData.append("mobile",$("#mobile").textbox('getValue'));
		formData.append("companyid",companyid);
		formData.append("departmentid",$("#department").combobox('getValue'));
		formData.append("projectitemid",projectItem.id);
		if(projectItemChild!=null){
			formData.append("projectitemchildid",projectItemChild.id);
		}
		formData.append("salary",$("#salary").textbox('getValue'));
		$.ajax({
			type : 'POST',
			url :  "../jobberSave.do",
			cache : false,
			data : formData,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存', '保存成功', 'success');
				} else {
					$.messager.alert('保存', '保存失败', 'error');
				}
				$('#levelchild').combotree('reload');
				$('#childDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	
	 function savePro() {
		var formData = new FormData();
		formData.append("projectitemid",projectItem.id);
		if(projectItemChild!=null){
			formData.append("projectitemchildid",projectItemChild.id);
		}
		formData.append("date",date);
		formData.append("duty",$("#levelchild").combotree('getValues'));
		var images = document.getElementById("filebox_file_id_1").files;
		for(var i=0;i<images.length;i++){
			formData.append('images',images[i]);
		}
		$.ajax({
			type : 'POST',
			url :  "../attendanceSave.do",
			cache : false,
			data : formData,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存', '保存成功', 'success');
				} else {
					$.messager.alert('保存', '保存失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	} 
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}

</script>
</html>